package com.xboard.server.dao.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.xboard.server.common.exception.DataAccessException;
import com.xboard.server.common.vo.UserVo;
import com.xboard.server.dao.UserDao;
import com.xboard.server.manager.DataManager;

/**
 * Handles requests for the application home page.
 */
@Repository
public class UserDaoImpl implements UserDao{

	@Autowired
	private DataManager dataManager;
	
	public UserDaoImpl(){
		
	}
	
	@Override
	public void addUser(UserVo user){
		try {
		    Key customerKey = KeyFactory.createKey("User", user.getId());
	        
		    Date date = new Date();
	        Entity enty = new Entity("User", customerKey);			
			enty.setProperty("id", user.getId());
			enty.setProperty("name", user.getName());
			enty.setProperty("email", user.getEmail());
			enty.setProperty("date", date);
			dataManager.insert(enty);
			
		} catch (Exception e) {
			throw new DataAccessException(e);
		}
	}
	@Override
	public List<UserVo> listUser(UserVo user){
		List<UserVo> rs = new ArrayList<UserVo>();
		try {
			
		} catch (Exception e) {
			throw new DataAccessException(e);
		}
		return rs;
	}
	@Override
	public void updateUser(UserVo user){
		try {
			
		} catch (Exception e) {
			throw new DataAccessException(e);
		}
	}
	@Override
	public void deleteUser(UserVo user){
		try {
			
		} catch (Exception e) {
			throw new DataAccessException(e);
		}
	}
}
